<?php

use Biz\service\search\Goods;
use Biz\tools\GoodsExposureLog;
use Doraemon\tools\ActionLog;
use Biz\service\SearchGoods as sSearchGoods;

/**
 * @deprecated
 */
class SearchGoodsAction extends ActionPlugin
{
    public function main()
    {
        $actionLogMap = [
            'default',
            'new',
            'price_asc',
            'price_desc',
        ];

        $keyword = $this->getRequest()->getQuery('keyword', '');
        $page = $this->getRequest()->getQuery('page', 1);
        $sort = $this->getRequest()->getQuery('sort_type', 0);
        $province_id = $this->getRequest()->getQuery('province_id', 0);
        $shop_id = $this->getRequest()->getQuery('shop_id', 0);
        $cityId = $this->getRequest()->getQuery('city_id', 0);
        $areaCode = $cityId ? $cityId : $province_id;
        // todo 搜索切换es待删除
        $goodsList = sSearchGoods::searchGoodsByShopTab($keyword, $shop_id, $sort, $areaCode, $page);

//        $goodsList = Goods::searchGoodsOnShop($keyword, $shop_id, $sort, $areaCode, $page);
        ActionLog::log($this->uid, [
            'shop_id' => $shop_id,
            'keyword' => $keyword,
            'page' => $page,
            'sort_type' => $actionLogMap[$sort]
        ], ActionLog::BIZ_SHOP_SEARCH_GOODS);

        $this->setSuccess($goodsList);
        GoodsExposureLog::addLog($this->getRequest(), $goodsList, $keyword);
    }
}